home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14329 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ix.netcom.com!news
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: overloading and ellipsis
  5. Date: 29 Mar 1996 17:16:34 GMT
  6. Organization: Netcom
  7. Message-ID: <4jh5ti$scq@dfw-ixnews6.ix.netcom.com>
  8. References: <tuka05p3gq.fsf@twit.informatik.uni-bremen.de>
  9. NNTP-Posting-Host: den-co11-03.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Fri Mar 29 11:16:34 AM CST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. In article <tuka05p3gq.fsf@twit.informatik.uni-bremen.de>, 
  16. thuerman@informatik.uni-bremen.de says...
  17. >
  18. >I'd like to overload a function with ellipsis but g++ doesn't let me
  19. >do that.  Should that be possible?
  20.  
  21. >void send(char *fmt, ...);
  22. >void send(char *s);
  23. >
  24. >main()
  25. >{
  26. >   send("abc\n");  // error:  ambiguous
  27. >}
  28. >
  29. >But nevertheless I would think that the third function matches better
  30. >than the first, so there would be exactly one best match and the call legal.
  31. >Does the ARM say something about this, and is g++ correct?
  32.  
  33. When the candidates for overload resolution are compared, they
  34. are all compared *as if* they had the same number of arguments.
  35. This means that:
  36.    void f(char*);
  37.    void f(char*, int x=1);
  38.    void f(char*, ...);
  39. When matched against the call to
  40.    f("string");
  41.  
  42. Are all evaluated as if they had one parameter of type char*.
  43. There is no comparison of "default", or "ellipsis" parameters
  44. that are unspecified in the function call, and so all are
  45. equivalent candidates.
  46.  
  47. Therefore, there is no "ellipsis match" to compare, and the
  48. call is ambiguous.
  49.  
  50. john lilley
  51.  
  52.